package com.eco.fanliapp.admin.controller.web;

import com.eco.fanliapp.admin.annotation.SysLogAnnotation;
import com.eco.fanliapp.admin.common.BaseController;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.entity.WebCircleFriends;
import com.eco.fanliapp.service.IWebCircleFriendsService;
import com.eco.fanliapp.utils.EmojiUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class WebCircleFriendsController extends BaseController {
    @Autowired
    private IWebCircleFriendsService circleFriendsService ;


    @RequestMapping(value = "/web/friends/selectWebCircleFriendsList", method = RequestMethod.GET)
    public ServerResponse<PageInfo> selectWebCircleFriendsList(@RequestParam(defaultValue = "1") Integer currentPage , @RequestParam(defaultValue = "5") Integer pageSize){
        Integer companyId = -1;
        if(getAuthentication().getRoleId() != 0){
            companyId = getAuthentication().getCompanyId();
        }
        return circleFriendsService.selectWebCircleFriendsList(companyId,currentPage,pageSize);
    }


    @SysLogAnnotation(value = "保存朋友圈",userType = 2)
    @RequestMapping(method = RequestMethod.POST,value = "/web/friends/save")
    public ServerResponse<PageInfo> updateWebCircleFriends(@RequestBody WebCircleFriends circleFriends){
        if (circleFriends == null){
            return ServerResponse.createByErrorMessage("请正确填写信息");
        }
        if(getAuthentication().getRoleId() != 0){
            circleFriends.setCompanyId(getAuthentication().getCompanyId());
        }
        circleFriends.setFriendName(EmojiUtil.resolveToByteFromEmoji(circleFriends.getFriendName()));
        circleFriends.setComments(EmojiUtil.resolveToByteFromEmoji(circleFriends.getComments()));
        circleFriends.setTitle(EmojiUtil.resolveToByteFromEmoji(circleFriends.getTitle()));
        return circleFriendsService.updateWebCircleFriends(circleFriends);

    }

    @SysLogAnnotation(value = "删除朋友圈",userType = 2)
    @RequestMapping(method = RequestMethod.GET, value = "/web/friends/delete")
    public ServerResponse<PageInfo> delete(int id){
        return circleFriendsService.delete(id);

    }

    @SysLogAnnotation(value = "更新朋友圈",userType = 2)
    @RequestMapping(method = RequestMethod.POST, value = "/web/friends/upstatus")
    public ServerResponse updateStatus(@RequestBody WebCircleFriends webCircleFriends){
        return circleFriendsService.updateStatus(webCircleFriends);

    }
}
